package com.pig4cloud.mall.order.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.pig4cloud.mall.order.entity.CompanyAddress;
import com.pig4cloud.mall.order.service.CompanyAddressService;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 公司收发货地址表
 *
 * @author fangyu
 * @date 2020-12-25 17:48:15
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/companyaddress")
@Api(value = "companyaddress" , tags = "公司收发货地址表管理")
public class CompanyAddressController {

    private final  CompanyAddressService companyAddressService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param companyAddress 公司收发货地址表
     * @return
     */
    @ApiOperation(value = "分页查询" , notes = "分页查询")
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('order_companyaddress_get')")
    public R getCompanyAddressPage(Page page, CompanyAddress companyAddress) {
        return R.ok(companyAddressService.page(page, Wrappers.query(companyAddress)));
    }


    /**
     * 通过id查询公司收发货地址表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询" , notes = "通过id查询")
    @GetMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('order_companyaddress_get')")
    public R getById(@PathVariable("id") Long id) {
        return R.ok(companyAddressService.getById(id));
    }

    /**
     * 新增公司收发货地址表
     * @param companyAddress 公司收发货地址表
     * @return R
     */
    @ApiOperation(value = "新增公司收发货地址表" , notes = "新增公司收发货地址表")
    @SysLog("新增公司收发货地址表")
    @PostMapping
    @PreAuthorize("@pms.hasPermission('order_companyaddress_add')")
    public R save(@RequestBody CompanyAddress companyAddress) {
        return R.ok(companyAddressService.save(companyAddress));
    }

    /**
     * 修改公司收发货地址表
     * @param companyAddress 公司收发货地址表
     * @return R
     */
    @ApiOperation(value = "修改公司收发货地址表" , notes = "修改公司收发货地址表")
    @SysLog("修改公司收发货地址表")
    @PutMapping
    @PreAuthorize("@pms.hasPermission('order_companyaddress_edit')")
    public R updateById(@RequestBody CompanyAddress companyAddress) {
        return R.ok(companyAddressService.updateById(companyAddress));
    }

    /**
     * 通过id删除公司收发货地址表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除公司收发货地址表" , notes = "通过id删除公司收发货地址表")
    @SysLog("通过id删除公司收发货地址表")
    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('order_companyaddress_del')")
    public R removeById(@PathVariable Long id) {
        return R.ok(companyAddressService.removeById(id));
    }

}
